package com.gagakuai.bpm.mqlistener.camunda.handler.withdraw;

import com.alibaba.fastjson.JSON;
import com.gagakuai.bpm.domian.dto.camunda.UserInfo;
import com.gagakuai.bpm.domian.entity.camuda.ActiInstEntity;
import com.gagakuai.bpm.mqlistener.camunda.baseproxy.BaseConsumer;
import com.gagakuai.bpm.service.camunda.WorkflowTaskService;
import com.gagakuai.bpm.utils.AssertUtils;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/*
 * @program: mss_server
 * @description:
 * @author: houhong
 * @create: 2022-03-29 12:38
 */
@Component
@Slf4j
public class BpmWithDrawConsumer implements BaseConsumer {

    @Resource
    private WorkflowTaskService workflowTaskService;


    /*
     * @param message 消息
     * @param channel 通道
     * @return
     * @Author houhong
     * @Description //TODO 实际类消费消息
     * @Date 11:00 上午 2022/3/25
     */
    @Override
    public void consume(Message message, Channel channel, String messageType) throws Exception {

        String str = new String(message.getBody());
        ActiInstEntity hiProcinst = JSON.parseObject(str, ActiInstEntity.class);

        log.info("=============进行撤销流程实际处理节点:{}================", hiProcinst.getProcInstId());
        UserInfo userInfo = new UserInfo();
        //设置办理人
        userInfo.setUserName(hiProcinst.getAssignee());
        userInfo.setUserId(hiProcinst.getAssignee());
        int reslut = workflowTaskService.withDraw(hiProcinst.getProcInstId(), userInfo);


        AssertUtils.assertWithDrawFailed(reslut);

        log.info("===================进行撤销流程处理成功==========================");
    }
}